package com.wn.excel.config;

import com.wn.excel.model.ColumnMapping;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @FileName: ExportProperties
 * @Description: 导出excel配置
 * @Author: MaWenHao
 * @Created: 2020/3/2 - 19:30
 * @Version: V1.0
 * @Company: 东方微银科技（北京）有限公司
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "woniu.export")
public class ExportTableProperties {
    /**
     * 导出的excel文件路径
     */
    private String filePath;
    /**
     * sheet页名称
     */
    private String sheetName = "模板";
    /**
     * Oracle数据库用户名
     */
    @Value("${spring.datasource.druid.username}")
    private String username;
    /**
     * 表名过滤规则
     */
    private List<String> filter;
    /**
     * 字段映射配置
     */
    private List<ColumnMapping> columnMapping;

    /**
     * 是否展示数据库用户名
     */
    private boolean exportUsername = true;
    /**
     * 是否展示主键
     */
    private boolean exportPrimaryKey = true;
    /**
     * 是否展示总记录数
     */
    private boolean exportTotalCount = true;
    /**
     * 是否展示补充说明
     */
    private boolean exportExtComment = false;

    /**
     * 初始化列名映射规则
     * @return
     */
    public static void initColumnMapping(ExportTableProperties exportTableProperties) {
        if (ObjectUtils.isEmpty(exportTableProperties.getColumnMapping())) {
            List<ColumnMapping> columnMappings = new ArrayList<>();
            columnMappings.add(new ColumnMapping("columnName", "列名", 50));
            columnMappings.add(new ColumnMapping("dataType", "数据类型(精度范围)", 50));
            columnMappings.add(new ColumnMapping("nullable", "允许为空Y/N", 50));
            columnMappings.add(new ColumnMapping("uniqueness", "唯一Y/N", 50));
            columnMappings.add(new ColumnMapping("dataDefault", "默认值", 50));
            columnMappings.add(new ColumnMapping("comments", "说明", 50));
            exportTableProperties.setColumnMapping(columnMappings);
        }
    }
}
